package com.gitee.wsl.markdown.html.tag

/*

import android.text.style.StrikethroughSpan
import org.commonmark.ext.gfm.strikethrough.Strikethrough
import io.noties.markwon.base.MarkwonVisitor
import io.noties.markwon.base.SpannableBuilder
import io.noties.markwon.base.html.*

class StrikeHandler : TagHandler() {
    override fun handle(
        visitor: MarkwonVisitor,
        renderer: MarkwonHtmlRenderer,
        tag: HtmlTag
    ) {
        if (tag.isBlock) {
            visitChildren(visitor, renderer, tag.asBlock)
        }
        (if (HAS_MARKDOWN_IMPLEMENTATION)
            getMarkdownSpans(visitor)
        else
            StrikethroughSpan())?.let {
            SpannableBuilder.setSpans(
                visitor.builder(),
                it,
                tag.start(),
                tag.end()
            )
        }
    }

    override fun supportedTags(): List<String> {
        return STRIKE_TAGS
    }

    companion object {
        // flag to detect if commonmark-java-strikethrough is in classpath, so we use SpanFactory
        // to obtain strikethrough span
        private  var HAS_MARKDOWN_IMPLEMENTATION = false

        val STRIKE_TAGS = listOf("s", "del")

        init {
            var hasMarkdownImplementation: Boolean
            try {
                // @since 4.3.1 we class Class.forName instead of trying
                //  to access the class by full qualified name (which caused issues with DexGuard)
                Class.forName("org.commonmark.ext.gfm.strikethrough.Strikethrough")
                hasMarkdownImplementation = true
            } catch (t: Throwable) {
                hasMarkdownImplementation = false
            }
            HAS_MARKDOWN_IMPLEMENTATION = hasMarkdownImplementation
        }

        private fun getMarkdownSpans(visitor: MarkwonVisitor): Any? {
            val configuration = visitor.configuration()
            val spanFactory = configuration.spansFactory(Strikethrough::class.java) ?: return null
            return spanFactory.getSpans(configuration, visitor.renderProps())
        }
    }
}*/
